import os

import ScheduleQuery
import Function.TaskManager as TaskManager
import Function.Account as Account
import FilesStatistics

def menu():
    while True:
        menu_list = ["添加任务", "查询课表", "文件统计", "账户管理", "刷新显示"]

        # 清屏
        os.system('cls')

        # 任务显示
        TaskManager.task_display()
        print("文本已复制")

        choose = menu_display(menu_list)
        os.system('cls')
        match choose:
            case 1:
                TaskManager.add_task()
            case 2:
                ScheduleQuery.menu()
            case 3:
                FilesStatistics.menu()
            case 4:
                Account.menu()
            case 5:
                continue
            case 0:
                break


def menu_display(menu_list: list) -> int:
    """
    显示菜单，并返回选择的值
    输入：菜单名称列表
    输出：打印整个菜单
    返回：选择的数字
    """
    while True:
        num = 0
        for item in menu_list:
            num += 1
            print(f"{num}.{item}")
        print("0.退出")

        try:
            choice_str = input("请输入序号：")
            choice_num = int(choice_str)
        except KeyboardInterrupt:
            os.system("cls")
            print("程序结束\n")
            return 0
        except ValueError:
            print("输入数字不为整数，请重新输入")
        else:
            return choice_num